package com.bobo.controller.base;


import com.bobo.annotations.RequestBody;
import com.bobo.annotations.RequestMapping;
import com.bobo.annotations.RequestMethod;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 * Created by anting on 16/10/24.
 */


public class BaseServlet2 extends HttpServlet {

//    @Override
//    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
//
//    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        response.setContentType("text/html;charset=utf-8");
//        request.setCharacterEncoding("utf-8");
//        response.setCharacterEncoding("utf-8");
//
//        String[] path = request.getRequestURI().split("/");
//        String pathMethod = "";
//        Method method = null;
//        //TODO 需要修改最后的链接   /admin/user/add      /user/add     /index
//        try {
//
//            pathMethod = path[path.length - 1 ];
//
//           //method = this.getClass().getDeclaredMethod(pathMethod, HttpServletRequest.class, HttpServletResponse.class);
//
//
//
//
//
//
//
//            Object result = method.invoke(this, request, response);
//
//            //是否存在  RequestBody 这个注解
//            boolean isBody =  method.isAnnotationPresent(RequestBody.class);
//
//
//            // 没有写判断是否存在,  直接取值
//
//            RequestMapping rm =  method.getAnnotation(RequestMapping.class);
//
//
//            String[] m =  rm.value();
//
//            System.out.println(Arrays.toString(m));
//
//
//            RequestMethod[] rmd =  rm.method();
//
//            for(RequestMethod r : rmd ) {
//
//                System.out.println(r);
//
//            }
//
//
//
//
//            if(isBody) {
//                PrintWriter out =  response.getWriter();
//                out.write(result.toString());
//
//            } else if (result.toString().startsWith("redirect:")) {
//                response.sendRedirect(result.toString().replace("redirect:", ""));
//            } else {
//                request.getRequestDispatcher("/" + result.toString() + ".jsp").forward(request, response);
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }

    public boolean eq(String q){
        if(q!=null && !"".equals(q.trim())){
            return true;
        }else {
            return false;
        }

    }
}
